#include "ros/ros.h"
#include <iostream>
#include "std_msgs/String.h"

using namespace std;

void topicCallback(const std_msgs::String::ConstPtr &msg) {
    cout << (*msg).data << endl;
}

int main(int argc, char **argv) {
    string nodeName = "cppsubscriber";
    string topicName = "cpptopic";

    //初始化节点
    ros::init(argc, argv, nodeName);
    ros::NodeHandle node;
    //创建订阅者
    const ros::Subscriber &subscriber = node.subscribe(topicName, 1000, topicCallback);
    // 阻塞线程
    ros::spin();
    return 0;
}